﻿namespace Microsoft.AspNetCore.App
{
    /// <summary>
    /// 用于写入终结点
    /// </summary>
    public static class EndpointHttpContextExtensions
    {
        public static Endpoint? GetEndpoint(this HttpContext context)
        {
            var endpointFeature = context.Features.Get<IEndpointFeature>();
            if (endpointFeature == null)
            {
                return null;
            }
            return endpointFeature.Endpoint;
        }

        public static void SetEndpoint(this HttpContext context, Endpoint endpoint)
        {
            context.Features.Set<IEndpointFeature>(new EndpointFeature(endpoint));
        }
    }
}
